package cn.iocoder.yudao.module.project.controller.admin.kismaterielexwarehouserecycle;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.project.controller.admin.kismaterielexwarehouserecycle.vo.*;
import cn.iocoder.yudao.module.project.dal.dataobject.kismaterielexwarehouserecycle.KisMaterielExWarehouseRecycleDO;
import cn.iocoder.yudao.module.project.service.kismaterielexwarehouserecycle.KisMaterielExWarehouseRecycleService;

@Tag(name = "管理后台 - 物料出库单作废信息")
@RestController
@RequestMapping("/project/kis-materiel-ex-warehouse-recycle")
@Validated
public class KisMaterielExWarehouseRecycleController {


    @Resource
    private KisMaterielExWarehouseRecycleService kisMaterielExWarehouseRecycleService;

    @PostMapping("/create")
    @Operation(summary = "创建物料出库单作废信息")
    // @PreAuthorize("@ss.hasPermission('project:kis-materiel-ex-warehouse-recycle:create')")
    public CommonResult<Long> createKisMaterielExWarehouseRecycle(@Valid @RequestBody KisMaterielExWarehouseRecycleSaveReqVO createReqVO) {
        return success(kisMaterielExWarehouseRecycleService.createKisMaterielExWarehouseRecycle(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新物料出库单作废信息")
    // @PreAuthorize("@ss.hasPermission('project:kis-materiel-ex-warehouse-recycle:update')")
    public CommonResult<Boolean> updateKisMaterielExWarehouseRecycle(@Valid @RequestBody KisMaterielExWarehouseRecycleSaveReqVO updateReqVO) {
        kisMaterielExWarehouseRecycleService.updateKisMaterielExWarehouseRecycle(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除物料出库单作废信息")
    @Parameter(name = "id", description = "编号", required = true)
    // @PreAuthorize("@ss.hasPermission('project:kis-materiel-ex-warehouse-recycle:delete')")
    public CommonResult<Boolean> deleteKisMaterielExWarehouseRecycle(@RequestParam("id") Long id) {
        kisMaterielExWarehouseRecycleService.deleteKisMaterielExWarehouseRecycle(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得物料出库单作废信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    // @PreAuthorize("@ss.hasPermission('project:kis-materiel-ex-warehouse-recycle:query')")
    public CommonResult<KisMaterielExWarehouseRecycleRespVO> getKisMaterielExWarehouseRecycle(@RequestParam("id") Long id) {
        KisMaterielExWarehouseRecycleDO kisMaterielExWarehouseRecycle = kisMaterielExWarehouseRecycleService.getKisMaterielExWarehouseRecycle(id);
        return success(BeanUtils.toBean(kisMaterielExWarehouseRecycle, KisMaterielExWarehouseRecycleRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得物料出库单作废信息分页")
    // @PreAuthorize("@ss.hasPermission('project:kis-materiel-ex-warehouse-recycle:query')")
    public CommonResult<PageResult<KisMaterielExWarehouseRecycleRespVO>> getKisMaterielExWarehouseRecyclePage(@Valid KisMaterielExWarehouseRecyclePageReqVO pageReqVO) {
        PageResult<KisMaterielExWarehouseRecycleDO> pageResult = kisMaterielExWarehouseRecycleService.getKisMaterielExWarehouseRecyclePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, KisMaterielExWarehouseRecycleRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出物料出库单作废信息 Excel")
    // @PreAuthorize("@ss.hasPermission('project:kis-materiel-ex-warehouse-recycle:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportKisMaterielExWarehouseRecycleExcel(@Valid KisMaterielExWarehouseRecyclePageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<KisMaterielExWarehouseRecycleDO> list = kisMaterielExWarehouseRecycleService.getKisMaterielExWarehouseRecyclePage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "物料出库单作废信息.xls", "数据", KisMaterielExWarehouseRecycleRespVO.class,
                        BeanUtils.toBean(list, KisMaterielExWarehouseRecycleRespVO.class));
    }

}